import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import svgLoader from 'vite-svg-loader'
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import styleImport, {VantResolve} from 'vite-plugin-style-import'
import {resolve} from 'path'
// 路径查找
const pathResolve = (dir: string): string => {
  return resolve(__dirname, '.', dir)
}

// 设置别名
const alias: Record<string, string> = {
  '/@': pathResolve('src'),
  '@': pathResolve('src'),
  '@build': pathResolve('build')
}
// https://vitejs.dev/config/
export default ({ mode }) => defineConfig({
  resolve: { alias },
  plugins: [
    vue(),
    styleImport({
      resolves: [VantResolve()]
    }),
    svgLoader(),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [pathResolve('src/assets/svg')],
      // 指定symbolId格式
      symbolId: 'icon-[dir]-[name]'
    })
  ],
  server: {
    open: true, //自动打开
    proxy: {
      '/api': {
        // target: 'http://apitest.wzxchat.cn/', //跨域地址  测试地址
        target:'https://tyapi.wzxchat.cn/', //生产环境
        changeOrigin: true, //是否允许跨域
      }
    }
  }
})

